//
//  FancyOrder.swift
//  Fancyswap
//
//  Created by Francois Gratton on 2015-04-12.
//  Copyright (c) 2015 Jonathan Muschalle. All rights reserved.
//

import Foundation

class FancyOrder {
    
    var id: Int = 0
    var item: FancyItem = FancyItem()
    var status: Int = 0
    var fromUser: String = ""
    var toUser: String = ""
    var balance: Int = 0
    
    init(){
    }
    
    /// create using json
    init (dic:NSDictionary) {
        let sjson = JSON(dic)

        for (key, value) in sjson
        {
            switch (key).lowercaseString
            {
            case "id":
                self.id = value.intValue
            case "status":
                self.status = value.intValue
            case "fromuser":
                self.fromUser = value.stringValue
            case "touser":
                self.toUser = value.stringValue
            case "userbalance":
                self.balance = value.intValue
            case "item":
                self.item = FancyItem(swiftyDic: value)
                
            default:
                println("Unknown element: \(key):\(value)")
            }
        }
    }

    func toString() -> String {
        return "id: \(id), status: \(status), fromUser: \(fromUser), toUser: \(toUser), balance: \(balance), item: \(item.toString())"
    }
}